package com.starnet.infocollecter;

import java.util.ArrayList;
import java.util.List;


import org.json.JSONObject;


import com.example.testinfocollect.SingleTool;
import com.starnet.constant.Constant;
import com.starnet.constant.WebJsonKey;
import com.starnet.sql.HandlerDataListTable;
import com.starnet.utils.CMDExecute;
import com.starnet.utils.Des3;
import com.starnet.utils.JsonTool;
import com.starnet.utils.net.NetTool;
import com.starnet.vo.ContactVo;
import com.starnet.vo.DataListVo;

import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.Cursor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * 收集信息的入口 只需要初始化此类，调用init()函数传入相应参数即可完成信息的收集
 * 
 * @author zmp
 * 
 */
public class InfoCollecter
{

	/**
	 * 上下文
	 */
	private Context context;

	/**
	 * 上传的服务器地址
	 */
	private String serveAddress;
	
	/**
	 * 获取到的信息
	 */
	private StringBuffer infoStr = new StringBuffer();
	
	private String userName;
	
	private String passW;
	
	/**
	 * 设备的ID上传时候用
	 */
	private String devicedId = "";
	
	private SharedPreferences sharedPreferences;
	
	/**
	 * 第一次打开应用
	 */
	private Boolean isFirstOpen = false;

	public InfoCollecter()
	{

	}

	/**
	 * 初始化信息收集器
	 * @param context上下文
	 * @param serveAddress 收集信息的http服务器地址
	 * @param userName 用户名
	 * @param passW 密码
	 */
	public void init(Context context, String serveAddress,String userName,String passW)
	{
		this.context = context;
		this.serveAddress = serveAddress;
		this.userName = userName;
		this.passW = passW;
		
		sharedPreferences = context.getSharedPreferences(Constant.SHARED_PREFERENCE	, 0);
		
		initSendData();
		
		try 
		{
			createDevicedId();
			getJsonData();
			getAllInfo(JsonTool.createJsonDataFormat(infoStr.toString()));
		} catch (Exception e) 
		{
			 e.printStackTrace();
		}
		
	}

	/**
	 * 获取所有的信息
	 */
	private void getAllInfo(String jsonData)  
	{
		if(TextUtils.isEmpty(jsonData)||jsonData.equals("{}"))
		{
			//没有要发送的数据
			SingleTool.addInfo("这次没有变化的数据");
			return;
		}
		
		//总共要发送的信息
		StringBuffer totalInfoStr = new StringBuffer();
		totalInfoStr.append("{");
		JsonTool.appendJsonItem(totalInfoStr, WebJsonKey.devicedId, devicedId);
		JsonTool.appendJsonItem(totalInfoStr, WebJsonKey.userName, userName);
		JsonTool.appendJsonItem(totalInfoStr, WebJsonKey.passW, passW);
		
		totalInfoStr.append("\""+WebJsonKey.jsonData+"\":");
		
		//data数据部分
		totalInfoStr.append(jsonData);//添加jsonData数据部分
		//data数据部分

		//结束的大括号
		totalInfoStr.append("}");
		
		String data = totalInfoStr.toString();
		
		//ceshi
        try
        {
        	SingleTool.addInfo(data);
        	JSONObject jsonObject = new JSONObject(data);
			SingleTool.addInfo("用户名： "+jsonObject.getString(WebJsonKey.userName));
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		//ceshi
		
		
		
		try 
		{
			data = Des3.encode(data);
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		//收集到的数据上传
		String dataId = System.currentTimeMillis()+"";//为每一个需要上传的数据赋予一个id
		HandlerDataListTable.insertDataToDataListTable(dataId, data, context);
		NetTool.uploadData(serveAddress,dataId, data,context);
	}
	
	/**
	 * 设置设备的ID号
	 */
	private void createDevicedId()
	{
		devicedId = sharedPreferences.getString(WebJsonKey.devicedId, "");
		
		if(TextUtils.isEmpty(devicedId))
		{
			//第一次打开应用
			TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			
			String imei = telephonyManager.getDeviceId();    //设置imei号
			
			devicedId = imei;//设置设备id
			
			if(TextUtils.isEmpty(devicedId))
			{
				devicedId = Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
			}

			if(TextUtils.isEmpty(devicedId))
			{
				devicedId = System.currentTimeMillis()+"";
			}
			
			sharedPreferences.edit().putString(WebJsonKey.devicedId, devicedId).commit();
			
			isFirstOpen = true;
		}
	}
	
	/**
	 * 获取要上传的数据内容
	 */
	private void getJsonData()
	{
		getScreenPiex();
		getWifiInfo();
		getTelePhonyManagerInfo();
		isTablet();
		getLocalPosition();
		getSysAllPackInfo();
		getBuildInfo();
		getSystemPropertyInfo();
		
	}

	/**
	 * 获取分辨率
	 * 只有在应用第一次打开的时候，才需要上传
	 */
	private void getScreenPiex() 
	{
		try 
		{
			if(isFirstOpen)
			{
				WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
				DisplayMetrics displayMetrics = new DisplayMetrics();
				windowManager.getDefaultDisplay().getMetrics(displayMetrics);
				JsonTool.appendJsonItem(infoStr, WebJsonKey.widthPixels, displayMetrics.widthPixels);
				JsonTool.appendJsonItem(infoStr, WebJsonKey.heightPixels, displayMetrics.heightPixels);
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	 /**
     * 获取wifi信息 
     * 信息有变化了，才上传
     */
    private void getWifiInfo()
    {
    	try 
    	{
    		WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            Boolean isWifiEnable = wifiManager.isWifiEnabled();
            String oldIsWifiEnable = sharedPreferences.getString(WebJsonKey.wifiEnabled, "");
            if(!oldIsWifiEnable.equals(isWifiEnable+""))
            {
            	//wifi状态变化
            	JsonTool.appendJsonItem(infoStr, WebJsonKey.wifiEnabled, isWifiEnable);
                sharedPreferences.edit().putString(WebJsonKey.wifiEnabled, isWifiEnable+"").commit();			
    		}
            
            
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            if(wifiInfo != null)
            {
    	        String mac = wifiInfo.getMacAddress();
    	        String oldMac = sharedPreferences.getString(WebJsonKey.wifiMac, "");
    	        if(!oldMac.equals(mac))
    	        {
    	        	JsonTool.appendJsonItem(infoStr, WebJsonKey.wifiMac, mac);
    	        	sharedPreferences.edit().putString(WebJsonKey.wifiMac, mac).commit();
    	        }
    	        
    	        String ssid = wifiInfo.getSSID();
	        	if(ssid == null)
	        	{
	        		ssid = "null";
	        	}
	        	String oldSsid = sharedPreferences.getString(WebJsonKey.wifissid, "null1010");
	        	if(!oldSsid.equals(ssid))
	        	{
	        		JsonTool.appendJsonItem(infoStr, WebJsonKey.wifissid, ssid);
                    sharedPreferences.edit().putString(WebJsonKey.wifissid, ssid).commit();	        		
	        	}
	        	
	        	int ipAddress = wifiInfo.getIpAddress();
	        	String oldIpAddres = sharedPreferences.getString(WebJsonKey.ipAddress, "null1010");
	        	if(!oldIpAddres.equals(ipAddress+""))
	        	{
	        		JsonTool.appendJsonItem(infoStr, WebJsonKey.ipAddress, ipAddress);
	        		sharedPreferences.edit().putString(WebJsonKey.ipAddress, ipAddress+"").commit();
	        	}
            }
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
    }
    
    
    /**
     * 比较两个对象是否相等
     * 不相等就替换
     * @param key
     * @param newValue
     */
    private void compareValue(String key,String newValue)
    {
    	if(newValue == null)
    	{
    		newValue = "null";
    	}
    	
    	String oldValue = sharedPreferences.getString(key, "null1010");
    	if(!oldValue.equals(newValue))
    	{
    		JsonTool.appendJsonItem(infoStr, key, newValue);
    		sharedPreferences.edit().putString(key, newValue).commit();
    	}
    }
    
    
    
	  /**
	     手机相关的信息
	  */
	private void getTelePhonyManagerInfo()
	{
		TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		try {
				String imei = telephonyManager.getDeviceId();    //设置imei号
				if(imei == null)
				{
					imei = "null";
				}
				String oldImei = sharedPreferences.getString(WebJsonKey.imei, "null1010");
				if(!oldImei.equals(imei))
				{
					JsonTool.appendJsonItem(infoStr, WebJsonKey.imei, imei);
					sharedPreferences.edit().putString(WebJsonKey.imei, imei).commit();
				}
		
				String operator = telephonyManager.getNetworkOperator();  
				if(!TextUtils.isEmpty(operator))
				{
				    int mcc = Integer.parseInt(operator.substring(0, 3));  
				    String oldMcc = sharedPreferences.getString(WebJsonKey.mcc, "");
				    
				    int mnc = Integer.parseInt(operator.substring(3));  
				    String oldMnc = sharedPreferences.getString(WebJsonKey.mnc, "");
				    	      
				    GsmCellLocation location = (GsmCellLocation) telephonyManager.getCellLocation();  
				    int lac = location.getLac();  
				    String oldLac = sharedPreferences.getString(WebJsonKey.lac, "");
				    
				    int cellid = location.getCid();  
				    String oldCellid = sharedPreferences.getString(WebJsonKey.cellid, "");
				    
				    if(!oldMcc.equals(mcc+""))
				    {
				    	JsonTool.appendJsonItem(infoStr, WebJsonKey.mcc, mcc);
		                sharedPreferences.edit().putString(WebJsonKey.mcc, mcc+"").commit();		    	
				    }
				    
				    if(!oldMnc.equals(mnc+""))
				    {
				    	JsonTool.appendJsonItem(infoStr, WebJsonKey.mnc, mnc);
		                sharedPreferences.edit().putString(WebJsonKey.mnc, mnc+"").commit();		    	
				    }
				    
				    if(!oldLac.equals(lac+""))
				    {
				    	JsonTool.appendJsonItem(infoStr, WebJsonKey.lac, lac);
		                sharedPreferences.edit().putString(WebJsonKey.lac, lac+"").commit();		    	
				    }
				
				    if(!oldCellid.equals(cellid+""))
				    {
				    	JsonTool.appendJsonItem(infoStr, WebJsonKey.cellid, cellid);
				    	sharedPreferences.edit().putString(WebJsonKey.cellid, cellid+"").commit();
				    }
				}
		
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		
//		 String phoneType;
//		//通信类型
//		 if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
//		 {
//			 phoneType = "GSM";
//		 }else if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA)
//		 {
//			 phoneType = "CDMA";
//		 }else{
//			 phoneType = "NONE";
//		 }
//		 
//		 JsonTool.appendJsonItem(infoStr, WebJsonKey.phoneType, phoneType);
		 
//		 String networkType;
//		//网络类型
//		 switch(telephonyManager.getNetworkType())
//		 {
//		 	case TelephonyManager.NETWORK_TYPE_EDGE:
//		 		networkType = "EDGE";
//		 		break;
//		 	case TelephonyManager.NETWORK_TYPE_GPRS:
//		 		networkType = "GPRS";
//		 		break;
//		 		default:
//		 			networkType = "NONE";
//		 }
		 
//		 JsonTool.appendJsonItem(infoStr, WebJsonKey.networkType, networkType);
		 
		 //是否漫游
//		 JsonTool.appendJsonItem(infoStr, WebJsonKey.networkRoaming, telephonyManager.isNetworkRoaming());
		 
		try 
		{
			//手机IMEI
			 String deviceSoftWarVersion = telephonyManager.getDeviceSoftwareVersion();
			 if(deviceSoftWarVersion == null)
			 {
				 deviceSoftWarVersion = "null";
			 }
			 String oldDeviceSoftVersion = sharedPreferences.getString(WebJsonKey.deviceSoftwareVersion, "null1010");
			 if(!oldDeviceSoftVersion.equals(deviceSoftWarVersion))
			 {
				 JsonTool.appendJsonItem(infoStr, WebJsonKey.deviceSoftwareVersion, deviceSoftWarVersion);
	             sharedPreferences.edit().putString(WebJsonKey.deviceSoftwareVersion, deviceSoftWarVersion).commit();			 
			 }
			 
			 //手机IMSI
			 String subscriberId = telephonyManager.getSubscriberId();
			 if(subscriberId == null)
			 {
				 subscriberId = "null";
			 }
			 String oldSubscriberId = sharedPreferences.getString(WebJsonKey.subscriberId, "null1010");
			 if(!oldSubscriberId.equals(subscriberId))
			 {
				 JsonTool.appendJsonItem(infoStr, WebJsonKey.subscriberId, subscriberId);
				 sharedPreferences.edit().putString(WebJsonKey.subscriberId, subscriberId).commit();
			 }
		} catch (Exception e) 
		{
			e.printStackTrace();
		}
		 
	}
    
    
	 /**
     * 判断是否是平板
     * 第一次打开才需要上传
     * @param  
     * @return
     */
     private  void isTablet( ) 
     {
    	if(isFirstOpen)
    	{
    		Boolean isTable = (context.getResources().getConfiguration().screenLayout& Configuration.SCREENLAYOUT_SIZE_MASK)>= Configuration.SCREENLAYOUT_SIZE_LARGE;
    		JsonTool.appendJsonItem(infoStr, WebJsonKey.isTable, isTable);
    	}
     }
     
     
    private MyLocationListener myLocationListener;
    private LocationManager locationManager;
     
     /**
     * 获取当前位置 
     */
    private void getLocalPosition()
     {
    	try {
		    	 locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);//获取LocationManager的一个实例
		    	 Boolean isGpsEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
		    	 Boolean isNetWorkEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
		    	 if(isGpsEnable||isNetWorkEnable)
		    	 {
		    		 Criteria criteria = new Criteria();
		    		 criteria.setAccuracy(Criteria.ACCURACY_FINE);
		    		 criteria.setCostAllowed(false); 
		    		 String providerName = locationManager.getBestProvider(criteria, true);
		
		    		 myLocationListener = new MyLocationListener();
		    		 
		    		 if (providerName != null)
		    		 {
		    			 locationManager.requestLocationUpdates(providerName, 0, 0, myLocationListener);
		    		 }else 
		    		 {
		    			 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, myLocationListener);
					 }
		    	 }
	    	} catch (Exception e)
	    	{
	    		 e.printStackTrace();
	    	}
     }
    
    private class MyLocationListener implements LocationListener
    {
		@Override
		public void onLocationChanged(Location location) 
		{
			try 
			{
				   String latitude = Double.toString(location.getLatitude());//经度
		   		   String longitude = Double.toString(location.getLongitude());//纬度
		   		   String altitude = Double.toString(location.getAltitude());//海拔

		   		   
		   		   String oldLatitude = sharedPreferences.getString(WebJsonKey.latitude, "null");
		   		   String oldLongitude = sharedPreferences.getString(WebJsonKey.longitude, "null");
		   		   String oldAltitude = sharedPreferences.getString(WebJsonKey.altitude, "null");
		   		   
		   		   if(latitude.equals(oldLatitude)&&longitude.equals(oldLongitude)&&altitude.equals(oldAltitude))
		   		   {
		   			   //地理位置完全没变化
		   		   }else 
		   		   {
		   			   SingleTool.addInfo("地理位置变化了");
					   //地理位置变化了 通知服务器
		   			   sharedPreferences.edit().putString(WebJsonKey.latitude, latitude).commit();
		   			   sharedPreferences.edit().putString(WebJsonKey.longitude, longitude).commit();
		   			   sharedPreferences.edit().putString(WebJsonKey.altitude, altitude).commit();
		   			   
		   			   StringBuffer locationInfo = new StringBuffer();
		   			   JsonTool.appendJsonItem(locationInfo, WebJsonKey.latitude, latitude);
		    		   JsonTool.appendJsonItem(locationInfo, WebJsonKey.longitude, longitude);
		    		   JsonTool.appendJsonItem(locationInfo, WebJsonKey.altitude, altitude);
		    		   
		    		   String jsonData = JsonTool.createJsonDataFormat(locationInfo.toString());
		    		   
		    		   getAllInfo(jsonData);
				   }
		   		   
		   		   if(myLocationListener != null)
		   		   {
		   			   locationManager.removeUpdates(myLocationListener);//获取到数据之后，就断开
		   		   }
			} catch (Exception e) 
			{
				e.printStackTrace();
			}
		}

		@Override
		public void onProviderDisabled(String provider) 
		{
		}

		@Override
		public void onProviderEnabled(String provider)
		{
			
		}

		@Override
		public void onStatusChanged(String provider, int status, Bundle extras)
		{
			
		}
    	
    }
    
    
    
    
    /**
     * 获取联系人数据
     */
    private void getContactsData()
    {
    	ArrayList<ContactVo> contactVos = new ArrayList<ContactVo>();
    	ContentResolver contentResolver = context.getContentResolver();
    	Cursor cursor = contentResolver.query(Phone.CONTENT_URI, new String[]{Phone.NUMBER,Phone.DISPLAY_NAME,Phone.CONTACT_ID}, null, null, null);
        if(cursor != null)
        {
        	while (cursor.moveToNext()) 
        	{
				String phoneNum = cursor.getString(0);
				if(TextUtils.isEmpty(phoneNum))
				{
					continue;
				}
				String phoneName = cursor.getString(1);
				long phoneId = cursor.getLong(2);
				ContactVo vo = new ContactVo();
				vo.phoneId = phoneId;
				vo.phoneName = phoneName;
				vo.phoneNum = phoneNum;
				contactVos.add(vo);
			}
        	
        	cursor.close();
        }
        
        JsonTool.appendJsonItem(infoStr, WebJsonKey.contactVo, contactVos);
    }
    
    
    
    /**
     * 操作系统版本
     */
    private void getVersionInfo()
    {
    	String result = "";
    	CMDExecute cmdExecute = new CMDExecute();
    	try 
    	{
			String[] args = {"/system/bin/cat","/proc/version"};
			result = cmdExecute.run(args, "system/bin/");
		} catch (Exception e) 
		{
			
		}
    	
    	JsonTool.appendJsonItem(infoStr, WebJsonKey.sysVer, result);
    }
    
    
    
    /**
     * 获取cpu信息
     */
    private void getCpuInfo()
    {
    	String result = "";
    	CMDExecute cmdExecute = new CMDExecute();
    	try 
    	{
			String[] args = {"/system/bin/cat","/proc/cpuinfo"};
			result = cmdExecute.run(args, "/system/bin/");
		} catch (Exception e) 
		{
			 
		}
    	
    	JsonTool.appendJsonItem(infoStr, WebJsonKey.cpuinfo, result);
    }
    
    
    /**
     * 获取系统所有包的信息
     */
    private void getSysAllPackInfo()
    {
    	try {
	    	  PackageManager packageManager = context.getPackageManager();
	    	  List<PackageInfo> pkgs = packageManager.getInstalledPackages(0);
	    	  
	    	  ArrayList<String> labels = new ArrayList<String>();
	    	  
	    	  StringBuffer packs = new StringBuffer();
	    	  
	    	  int len = pkgs.size();
	    	  for (int i=0; i<len; i++)
	    	  {
	    	      PackageInfo info = pkgs.get(i);
	    	      String label = info.applicationInfo.loadLabel(context.getPackageManager()).toString();
	    	      labels.add(label);
	    	      packs.append(label);
	    	  }
	    	  
	    	  String oldPacks = sharedPreferences.getString(WebJsonKey.sysAllPackInfo, "");
	          if(!oldPacks.equals(packs.toString()))
	          {
	        	  JsonTool.appendJsonItemLabels(infoStr, WebJsonKey.sysAllPackInfo, labels);
	              sharedPreferences.edit().putString(WebJsonKey.sysAllPackInfo, packs.toString()).commit();        	  
	          }
    	} catch (Exception e) 
    	{
    		e.printStackTrace();
		}
    	  
    }
    
    /**
     *  和设备有关的硬件产商信息 
     *  应用第一次打开获取
     */
    private void getBuildInfo()
    {
    	if(isFirstOpen)
    	{
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.MODEL, Build.MODEL);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.VERSIONSDK, Build.VERSION.SDK);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.VERSIONRELEASE, Build.VERSION.RELEASE);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.BOARD, Build.BOARD);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.BRAND, Build.BRAND);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.CPU_ABI, Build.CPU_ABI);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.CPU_ABI2, Build.CPU_ABI2);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.DEVICE, Build.DEVICE);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.DISPLAY, Build.DISPLAY);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.FINGERPRINT, Build.FINGERPRINT);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.HOST, Build.HOST);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.HARDWARE, Build.HARDWARE);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.ID, Build.ID);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.MANUFACTURER, Build.MANUFACTURER);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.MODEL, Build.MODEL);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.PRODUCT, Build.PRODUCT);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.SERIAL, Build.SERIAL);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.TAGS, Build.TAGS);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.TIME, Build.TIME+"");
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.TYPE, Build.TYPE);
	       JsonTool.appendJsonItem(infoStr, WebJsonKey.USER, Build.USER);
    	}
    }
    
    
    /**
     * 系统信息
     */
    private void getSystemPropertyInfo()
    {
    	if(isFirstOpen)
    	{
    		JsonTool.appendJsonItem(infoStr, WebJsonKey.osversion, System.getProperty("os.version"));
    		JsonTool.appendJsonItem(infoStr, WebJsonKey.osname, System.getProperty("os.name"));
    		JsonTool.appendJsonItem(infoStr, WebJsonKey.osarch, System.getProperty("os.arch"));
    	}
    }
    
    
    
    /**
     * 启动的时候，检测是否有未发送成功的数据
     * 有的话，发送数据
     */
    private void initSendData()
    {
    	ArrayList<DataListVo> vos = HandlerDataListTable.getDataListRecord(context);
    	int len = vos.size();
    	SingleTool.addInfo("上次未发送的数据有："+len+" 条");
    	for (int i = 0; i < len; i++) 
    	{
			DataListVo vo = vos.get(i);
			SingleTool.addInfo("dataId = "+vo.dataId+"	dataString = "+vo.dataString);
			NetTool.uploadData(serveAddress,vo.dataId, vo.dataString,context);
		}
    }
    
    /**
     * 释放资源
     */
    public void onDestroy()
    {
    	NetTool.onDestroy(context);
    	infoStr = new StringBuffer();
    }

}
